﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExamAnalysis.Model;

namespace ExamAnalysis.Controls
{
    public partial class DropDownSchoolList : System.Web.UI.UserControl
    {
        public event EventHandler SelectedSchoolChanged; //添加事件句柄 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindSchool();
            }
        }

        public void BindSchool()
        {
            using (ExamAnalysisDataContext db = new ExamAnalysisDataContext())
            {
                SchoolList.DataSource = db.SchoolInfo.ToList();
                SchoolList.DataTextField = "FullName";
                SchoolList.DataValueField = "SchoolID";
                SchoolList.DataBind();
            }
        }

        protected void SchoolList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (SelectedSchoolChanged != null)
            {
                SelectedSchoolChanged(this, new EventArgs()); //激活SelectedSchoolChanged事件   
            }
        }

        #region

        public Unit Width
        {
            get 
            { 
                return SchoolList.Width; 
            }
            set 
            { 
                SchoolList.Width = value; 
            }
        }
        public int SchoolID
        {
            get
            {
                return Convert.ToInt32(SchoolList.SelectedValue);
            }
            set
            {
                if (SchoolList.Items.Count > 0)
                {
                    SchoolList.SelectedValue = value.ToString();
                }
            }
        }

        #endregion
    }
}